<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增商品')" />
	<style>
		.file {
			position: relative;
			display: inline-block;
			background: #D0EEFF;
			border: 1px solid #99D3F5;
			border-radius: 4px;
			padding: 4px 12px;
			overflow: hidden;
			color: #1E88C7;
			text-decoration: none;
			text-indent: 0;
			line-height: 20px;
		}
		.file input {
			position: absolute;
			font-size: 100px;
			right: 0;
			top: 0;
			opacity: 0;
		}
		.file:hover {
			background: #AADFFD;
			border-color: #78C3F3;
			color: #004974;
			text-decoration: none;
		}
		.showImg{
			width: 100px;
			height: 100px;
			border: 1px solid #ccc;
		}
	</style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goodsInfo-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">商品名称：</label>
				<div class="col-sm-8">
					<input id="productName" name="productName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">商品价格：</label>
				<div class="col-sm-8">
					<input id="price" name="price" class="form-control" type="text">
				</div>
			</div>
<!--			<div class="form-group">	-->
<!--				<label class="col-sm-3 control-label">刷单总量限制：</label>-->
<!--				<div class="col-sm-8">-->
<!--					<input id="clickCount" name="clickCount" class="form-control" type="text">-->
<!--				</div>-->
<!--			</div>-->
<!--			<div class="form-group">	-->
<!--				<label class="col-sm-3 control-label">当前已刷次数：</label>-->
<!--				<div class="col-sm-8">-->
<!--					<input id="totlaCount" name="totlaCount" class="form-control" type="text">-->
<!--				</div>-->
<!--			</div>-->
			<div class="form-group">
				<label class="col-sm-3 control-label">图片缩略图：</label>
				<div class="col-sm-8">
					<div class="showImg">
						<img id="previewImg" style="visibility: hidden; height: 90px;width: 90px;" src=""/>
					</div>
					<a href="javascript:;" class="file">选择文件
						<input id="_imgUrl" name="_imgUrl" type="file">
					</a>
					<span>必传，正方形，建议尺寸300*300以上  .jpg</span>
					<input id="imgUrl" name="imgUrl" class="form-control" type="hidden">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var imgUrl ='';
		$("#_imgUrl").change(function () {
			//创建blob对象，浏览器将文件放入内存中，并生成标识
			var file = $(this)[0].files[0];
			var img_src = URL.createObjectURL(file);
			//给img标检的src赋值
			document.getElementById("previewImg").src=img_src;
			$("#previewImg").css("visibility","visible");
			//URL.revokeObjectURL(img_src);// 手动 回收，
			var data = new FormData();
			data.append("file", file);
			$.ajax({
				type: "POST",
				url: ctx + "common/upload",
				data: data,
				cache: false,
				contentType: false,
				processData: false,
				dataType: 'json',
				success: function(result) {
					if (result.code == web_status.SUCCESS) {
						$.modal.alert('上传成功！');
						$('#imgUrl').val( result.url );
					} else {
						$.modal.alertError(result.msg);
					}
				},
				error: function(error) {
					$.modal.alertWarning("图片上传失败。");
				}
			});
		});

		var prefix = ctx + "channel/goodsInfo"
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-goodsInfo-add').serialize());
	        }
	    }
	</script>
</body>
</html>
